package at.fhooe.mcm12.java.sensors;

import java.util.Iterator;
import java.util.Vector;
import at.fhooe.mcm12.java.interfaces.INMEAListener;
import at.fhooe.mcm12.java.interfaces.ISensorListener;
import at.fhooe.mcm12.java.parser.NMEAParser;
import at.fhooe.mcm12.java.sensors.data.GPSPosition;

public class GPSSensor extends PushSensor<GPSPosition> implements INMEAListener{

	private GPSPosition m_currentPosition = null;
	private NMEAParser m_parser = null;
	
	public GPSSensor()
	{
		m_sensorListener = new Vector<ISensorListener<?>>();
		m_parser = new NMEAParser();
		m_parser.addNMEAListener(this);
		m_parser.start();
		
		Thread t = new Thread(this);
		t.start();
	}
	
	@Override
	public void push() {
		
		if(m_currentPosition != null)
		{
			for(ISensorListener listener : m_sensorListener)
			{
				listener.onSensorValueReceived(m_currentPosition);
			}
		}
	}

	@Override
	public void inform(GPSPosition _position) {
		if(_position != null)
		{
			m_currentPosition = _position;
		}
	}
}
